<?php

require_once 'classes/LightPressPlugin.php';

class PostAd extends LightPressPlugin {
    
    var $constructor_args = array(
        'activate_at'=>'after which post to display the ad');
    var $default_context = 7; // LP_CONTEXT_INDEX | LP_CONTEXT_ARCHIVES | LP_CONTEXT_CATEGORY;
    var $description = 'Insert an HTML snippet between posts in the index';
    

    var $active = true;
    var $hooks = array('parse_post');

    var $activate_at = 3;
    var $_loop_cycle = 0;

    function PostAd(&$frontend, $args, $dummy_run=false) {
        $this->LightPressPlugin($frontend, $args, $dummy_run);

        if (!$dummy_run) {
            $this->activate_at = (int)$this->activate_at;
        
            if ($frontend->options['posts_per_page'] >= $this->activate_at)
                $active = false;
        }
    }

    function hide() {
        return;
    }
    
    function run($hook, &$post) {
        $this->_loop_cycle++;
        if ($this->activate_at != $this->_loop_cycle)
            return;
        $tpl =& $this->_frontend->tpl;
        $tpl->setFile('plugin_postad', 'plugins/post_ad.xml');
        $tpl->parse('BLOCK_POST', 'plugin_postad', true);
    }

}

?>